#pragma once

#include <QString>
#include <QList>

enum UsbType {
    USB_NONE = 0,
    USB_200 = 200,
    USB_300 = 300,
    USB_310 = 310,
    USB_320 = 320,
};

struct DataItem
{
    DataItem(const QString &_sn, const QString &_name, bool _hotspot = false, int _usb = 0, const QString &_note = QString())
        : sn(_sn), name(_name), hotspot(_hotspot), usb(_usb), note(_note) {}
    QString sn;
    QString name;
    bool hotspot;
    int usb;
    QString note;
};


class Table {
public:
    enum SaveFormat {
        JsonFormat = 0,
        DBFormat
    };

    Table();
    ~Table();

    QList<DataItem *> &data();
    void setData(const QList<DataItem *> &newData);
    void addDataItem(DataItem *item);
    void addDataItem(const QString &_sn, const QString &_name, bool _hotspot = false, int _usb = 0, const QString &_note = QString());
    void clearAll();

    bool load(const QString &fileName, SaveFormat format = JsonFormat, bool clearOldData = true);
    bool save(const QString &fileName, SaveFormat format = JsonFormat);

private:
    bool loadFromJson(const QString &fileName, QList<DataItem *> &datas);
    bool loadFromDatabase(const QString &fileName, QList<DataItem *> &datas);

    bool saveToJson(const QString &fileName, const QList<DataItem *> &datas);
    bool saveToDatabase(const QString &fileName, const QList<DataItem *> &datas);

private:
    QList<DataItem *> m_datas;
};
